var inn=document.getElementById('time');
function checkTime(time){
    if(time<10){
        time="0"+time;
    }
    return time;
}
function time1(){
    var date = new Date();
    var month = checkTime(date.getMonth()+1);
    var year=date.getFullYear();
    var day=checkTime(date.getDate());
    var week = date.getDay();
    var hour = checkTime(date.getHours());
    var min = checkTime(date.getMinutes());
    var sec = checkTime(date.getSeconds());
    var week1;
    switch(week)
    {
        case 0: week1='星期日'; break;
        case 1: week1='星期一'; break;
        case 2: week1='星期二'; break;
        case 3: week1='星期三'; break;
        case 4: week1='星期四'; break;
        case 5: week1='星期五'; break;
        case 6: week1='星期六'; break;
    }
    inn.innerHTML=year+'-'+month+'-'+day+' '+week1+' '+hour+':'+min+':'+sec;
    var innn=inn.innerHTML;
    setTimeout(time1,1000);
}
time1();

function quere() {
    var num = 5;
    if ($('#demo1').height() - $('#demo').scrollTop() >= num) {
        $('#demo').scrollTop($('#demo').scrollTop() + num);
    } else {
        $('#demo').scrollTop(num- ($('#demo1').height() - $('#demo').scrollTop()));
    }
}

var myChart = echarts.init(document.getElementById('map'));

var geoCoorddata = {
    '安徽': [117.283042,31.86119],
    '澳门': [113.5528956,22.20787],
    '北京': [116.418757,39.917544],
    '重庆': [108.380246,30.807807],
    '福建': [119.306239,26.075302],
    '甘肃': [103.823557,36.058039],
    '广东': [113.280637,23.125178],
    '广西': [108.320004,22.82402],
    '贵州': [106.713478,26.578343],
    '海南': [110.33119,20.031971],
    '河北': [114.502461,38.045474],
    '黑龙江': [126.642464,45.756967],
    '河南': [113.665412,34.757975],
    '湖北': [114.298572,30.584355],
    '湖南': [112.982279,28.19409],
    '江苏': [118.767413,32.041544],
    '江西': [115.892151,28.676493],
    '吉林': [125.3245,43.886841],
    '辽宁': [123.429096,41.796767],
    '内蒙古': [111.670801,40.818311],
    '宁夏': [106.278179,38.46637],
    '青海': [101.778916,36.623178],
    '山东': [117.000923,36.675807],
    '上海': [121.490317,31.222771],
    '山西': [112.549248,37.857014],
    '陕西': [108.948024,34.263161],
    '四川': [104.065735,30.659462],
    '台湾': [121.509062,25.044332],
    '天津': [117.195907,39.118327],
    '香港': [114.1543731,22.28198083],
    '新疆': [87.617733,43.792818],
    '西藏': [91.132212,29.660361],
    '云南': [102.712251,25.040609],
    '浙江': [120.153576,30.287459]
};
option = {
    animation : false,
    //bmap: {
    //center: [116.418261, 39.921984],
    //zoom:5,
    //roam: true
    //},
    bmap : {
        center : [ 106.018261, 32.921984 ],
        zoom : 5,
        roam : false,
        mapStyle : {
            styleJson : [ {
                "featureType" : "water",
                "elementType" : "all",
                "stylers" : {
                    //"color" : "#044161"
                    "color" : "#050C39"
                    //"color" : "#000011"
                }
            }, {
                "featureType" : "land",
                "elementType" : "all",
                "stylers" : {
                    //"color" : "#004981"
                    "color" : "#050C39"
                    //"color" : "#000000"
                }
            }, {
                "featureType" : "boundary",
                "elementType" : "geometry",
                "stylers" : {
                    //"color" : "#064f85"
                }
            }, {
                "featureType" : "railway",
                "elementType" : "all",
                "stylers" : {
                    "visibility" : "off"
                }
            }, {
                "featureType" : "highway",
                "elementType" : "geometry",
                "stylers" : {
                    "color" : "#004981"
                }
            }, {
                "featureType" : "highway",
                "elementType" : "geometry.fill",
                "stylers" : {
                    "color" : "#005b96",
                    "lightness" : 1
                }
            }, {
                "featureType" : "highway",
                "elementType" : "labels",
                "stylers" : {
                    "visibility" : "off"
                }
            }, {
                "featureType" : "arterial",
                "elementType" : "geometry",
                "stylers" : {
                    "color" : "#004981"
                }
            }, {
                "featureType" : "arterial",
                "elementType" : "geometry.fill",
                "stylers" : {
                    "color" : "#00508b"
                }
            }, {
                "featureType" : "poi",
                "elementType" : "all",
                "stylers" : {
                    "visibility" : "off"
                }
            }, {
                "featureType" : "green",
                "elementType" : "all",
                "stylers" : {
                    "color" : "#056197",
                    "visibility" : "off"
                }
            }, {
                "featureType" : "subway",
                "elementType" : "all",
                "stylers" : {
                    "visibility" : "off"
                }
            }, {
                "featureType" : "manmade",
                "elementType" : "all",
                "stylers" : {
                    "visibility" : "off"
                }
            }, {
                "featureType" : "local",
                "elementType" : "all",
                "stylers" : {
                    "visibility" : "off"
                }
            }, {
                "featureType" : "arterial",
                "elementType" : "labels",
                "stylers" : {
                    "visibility" : "off"
                }
            }, {
                "featureType" : "boundary",
                "elementType" : "geometry.fill",
                "stylers" : {
                    "color" : "#029fd4"
                }
            }, {
                "featureType" : "building",
                "elementType" : "all",
                "stylers" : {
                    "color" : "#1a5787"
                }
            }, {
                "featureType" : "label",
                "elementType" : "all",
                "stylers" : {
                    "visibility" : "off"
                }
            } ]
        }
    },
    series : [ {
        type: 'effectScatter',
        mapType: 'china',
        coordinateSystem: 'bmap',
        zlevel: 3,
        data: [],
        label: {
            normal: {
                show: false,
                position: 'right',
                formatter: '{b}'
            },emphasis: {
                show:true,
                formatter: function (params) {
                    return params.name+':'+params.value[2] ;
                }
            }
        },
        symbolSize: function (val) {
            return val[2]/18;
        },
        rippleEffect: {
            period: 10,
            scale: 5,
            brushType: 'stroke'
        },
        itemStyle: {
            normal: {
                color: '#FEE619',
            }
        },
    } ]
};
myChart.setOption(option);
// 添加百度地图插件
var bmap = myChart.getModel().getComponent('bmap')
    .getBMap();
bmap.addControl(new BMap.MapTypeControl());

var timer;
var delayTimer;
hotScenicSpot();
spotTimer = setInterval(hotScenicSpot, 1000*60*5);

function hotScenicSpot() {
    $.ajax({
        url : "/rhino/homePage/hotScenicSpot",
        type:'post',
        data : {
        },
        dataType : "json",
        success : function(data) {
            if(!$.isEmptyObject(data)){
                var totalOrderQuantity = data.totalOrderQuantity;
                $("#totalOrderQuantity").html(totalOrderQuantity);

                clearInterval(timer);//滚屏定时器
                clearTimeout(delayTimer);//当请求返回的数据为空对象时，触发延时请求

                //热门景区的滚屏展示
                var productList = data.productList;
                if(productList != null){
                    var html = '';
                    for(var i=0;i<productList.length;i++){
                        var index = i+1;
                        var productName = productList[i].productName;
                        var views = productList[i].views;
                        html += '<tr><td><div>'+index+'</div></td><td>'+productName+'</td><td>'+ views+'</td></tr>';
                    }
                    $("#demo1").html(html);
                    if ($('#demo1').height() < $('#demo').height()) {
                        $('#demo2').html('');
                    }else{
                        $('#demo').scrollTop(0);
                        $('#demo2').html($('#demo1').html());
                        timer = setInterval(quere, 200);
                    }
                }

                //地区订单
                var provinceLegend = data.provinceLegend;
                var payComplete = data.payComplete;
                var orderQuantity = data.orderQuantity;
                option1.yAxis[0].data = provinceLegend;
                option1.yAxis[1].data = provinceLegend;
                option1.series[0].data=orderQuantity;
                option1.series[1].data=payComplete;
                myChart1.setOption(option1,true);

                //订单占比
                var provinceSeries = data.provinceSeries;
                option9.series[0].data=provinceSeries;
                //option9.legend.data=provinceLegend;
                myChart9.setOption(option9,true);

                //运营商订单
                var orderTime = data.orderTime;
                var CMOrder = data.CMOrder;
                var CUOrder = data.CUOrder;
                var CTOrder = data.CTOrder;
                var otherOrder = data.otherOrder;
                option8.xAxis[0].data = orderTime;
                option8.series[0].data=CMOrder;
                option8.series[1].data=CUOrder;
                option8.series[2].data=CTOrder;
                option8.series[3].data=otherOrder;
                myChart8.setOption(option8,true);

                //订单统计
                var XAxisList = data.XAxisList;
                var orderDataMap = data.orderDataMap;
                var provinceMap = data.provinceMap;
                var optionsArr = new Array();
                for(var i=0;i<XAxisList.length;i++){
                    var key = XAxisList[i];
                    var obj =new Object();
                    var seriesArr = new Array();
                    var itemStyleObj = new Object();
                    var normalObj = new Object();
                    var textObj = new Object();
                    var seriesObj = new Object();
                    normalObj.color = '#13AEFE';
                    normalObj.opacity = 0.5;
                    itemStyleObj.normal=normalObj;
                    seriesObj.itemStyle=itemStyleObj;
                    seriesObj.data=orderDataMap[key];
                    seriesArr.push(seriesObj);
                    var xAxisArr = new Array();
                    var xAxisObj = new Object();
                    xAxisObj.data = provinceMap[key];
                    xAxisObj.type = 'category';
                    xAxisArr.push(xAxisObj);
                    textObj.text=key+"下单量";
                    obj.title= textObj;
                    obj.series=seriesArr;
                    obj.xAxis=xAxisArr
                    optionsArr[i]=obj;
                }
                option7.baseOption.timeline.data=XAxisList;
                option7.options=optionsArr;
                myChart7.setOption(option7,true);
                //alert(JSON.stringify(optionsArr));

                //地图的订单展示
                var newList = data.newList;
                var arg = new Array();
                for (var i=0;i<newList.length;i++){
                    var obj = new Object();
                    var name = newList[i].province;
                    var value = newList[i].count;
                    var geo = geoCoorddata[name];
                    if(geo == undefined){
                        continue;
                    }
                    obj.name = name;
                    obj.value = geoCoorddata[name].concat(value);
                    arg.push(obj);
                }
                option.series[0].data=arg;
                myChart.setOption(option,true);
                //$(".anchorBL").remove();
            }else{
                delayTimer = setTimeout(hotScenicSpot, 1000*10);
            }
        }
    });
}

var myChart1 = echarts.init(document
    .getElementById('main1'));

//地区订单
// 指定图表的配置项和数据
var option1 = {
    tooltip : {
        trigger: 'axis',
        axisPointer : {            // 坐标轴指示器，坐标轴触发有效
            type : 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
        },
    },
    legend: {
        bottom: 20,
        textStyle:{
            color:'#fff',
            fontStyle: 'oblique',
            fontWeight: 'bold',
            fontSize: 15,
        },
        data: ['支付完成量', '订单量']
    },
    grid: {
        top:'-1%',
        right: '-2%',
        left: '1%',
        containLabel: true
    },
    xAxis:  {
        type: 'value',
        axisTick : {show: false},
        axisLine: {
            show: false,
            lineStyle:{
                color:'#fff',
            }
        },
        axisLabel: {
            textStyle: {
                color: 'white',
                fontStyle: 'oblique',
                fontWeight: 'bold',
                fontSize: 15,
            }
        },
        splitLine: {
            show: false
        },
    },
    yAxis: [
        {
            type: 'category',
            axisTick : {show: false},
            axisLine: {
                show: false,
                lineStyle:{
                    color:'#fff',
                }
            },
            axisLabel: {
                textStyle: {
                    color: 'white',
                    fontStyle: 'oblique',
                    fontWeight: 'bold',
                    fontSize: 15,
                }
            },
            data: []
        },
        {
            type: 'category',
            axisLine: {show:false},
            axisTick: {show:false},
            axisLabel: {show:false},
            splitArea: {show:false},
            splitLine: {show:false},
            data: []
        },

    ],
    series: [
        {
            name: '订单量',
            type: 'bar',
            yAxisIndex:1,
            itemStyle:{
                normal: {
                    show: true,
                    color: '#277ace',
                    barBorderRadius:50,
                    borderWidth:0,
                    borderColor:'#333',
                    opacity:0.6,
                }
            },
            barGap:'0%',
            barCategoryGap:'50%',
            data: []
        },
        {
            name: '支付完成量',
            type: 'bar',
            itemStyle:{
                normal: {
                    show: true,
                    color: '#5de3e1',
                    barBorderRadius:50,
                    borderWidth:0,
                    borderColor:'#333',
                    opacity:0.6,
                }
            },
            barGap:'0%',
            barCategoryGap:'50%',
            data: []
        }

    ]
};

// 使用刚指定的配置项和数据显示图表。
myChart1.setOption(option1);

//订单统计
var myChart7 = echarts.init(document
    .getElementById('main7'));
option7 = {
    baseOption: {
        timeline: {
            axisType: 'category',
            autoPlay: true,
            playInterval: 1000*5,
            itemStyle: {
                normal: {
                    color: '#fff',
                }
            },
            label: {
                normal: {
                    textStyle: {
                        color: 'white',
                        fontStyle: 'oblique',
                        fontWeight: 'bold',
                        //fontSize: 2,
                    }
                }
            },
            data: [],
        },
        title: {
            textStyle:{
                color:'#fff',
                fontStyle: 'oblique',
                fontWeight: 'bold',
                fontSize: 18,
            },
            subtextStyle: {
                color:'#fff',
                fontStyle: 'oblique',
                fontWeight: 'bold',
                fontSize: 12,
            }
        },
        tooltip: {
        },
        calculable : true,
        grid: {
            top: 45,
            bottom: 100,
            tooltip: {
                trigger: 'axis',
                axisPointer: {
                    type: 'shadow',
                    label: {
                        show: true,
                        formatter: function (params) {
                            return params.value.replace('\n', '');
                        }
                    }
                }
            }
        },
        xAxis: [
            {
                type:'category',
                axisLabel:{
                    textStyle: {
                        color: 'white',
                        fontStyle: 'oblique',
                        fontWeight: 'bold',
                        fontSize: 1,
                    },
                    'interval':0
                },
                data:[
                    '北京','\n天津','河北','\n山西','内蒙古','\n辽宁','吉林','\n黑龙江',
                    '上海','\n江苏','浙江','\n安徽','福建','\n江西','山东','\n河南',
                    '湖北','\n湖南','广东','\n广西','海南','\n重庆','四川','\n贵州',
                    '云南','\n西藏','陕西','\n甘肃','青海','\n宁夏','新疆'
                ],
                splitLine: {show: false}
            }
        ],
        yAxis: [
            {
                type: 'value',
                //name: '一小时内下单数量',
                nameTextStyle: {
                    color: 'white',
                    fontStyle: 'oblique',
                    fontWeight: 'bold',
                    fontSize: 10,
                },
                axisLabel: {
                    textStyle: {
                        color: 'white',
                        fontStyle: 'oblique',
                        fontWeight: 'bold',
                        fontSize: 15,
                    }
                },
                splitLine: {
                    show: true,
                    lineStyle: {
                        color: ['#ccc'],
                        type: 'dashed',
                        opacity:0.5,
                    }
                },
            }
        ],
        series: [
            {name: '下单数量', type: 'bar',barWidth: '23px'},
        ]
    },
    options: []
};

myChart7.setOption(option7);

//运营商订单
var myChart8 = echarts.init(document
    .getElementById('main8'));
option8 = {
    title: {
        text: '订单量',
        textStyle:{
            color:'#fff',
            fontStyle: 'oblique',
            fontWeight: 'bold',
            fontSize: 15,
        },
        left: '6%'
    },
    tooltip: {
        trigger: 'axis',
        axisPointer: {
            lineStyle: {
                color: '#57617B'
            }
        }
    },
    legend: {
        icon: 'rect',
        itemWidth: 14,
        itemHeight: 5,
        itemGap: 13,
        data: ['移动', '电信', '联通','其他'],
        right: '4%',
        textStyle:{
            color:'#fff',
            fontStyle: 'oblique',
            fontWeight: 'bold',
            fontSize: 15,
        },
    },
    grid: {
        top:'1.5%',
        right: '5%',
        left: '2%',
        containLabel: true
    },
    xAxis: [{
        type: 'category',
        boundaryGap: false,
        axisLine: {
            lineStyle: {
                color: '#57617B'
            }
        },
        axisLabel: {
            textStyle: {
                color: 'white',
                fontStyle: 'oblique',
                fontWeight: 'bold',
                fontSize: 13,
            }
        },
        data: []
    }],
    yAxis: [{
        type: 'value',
        name: '单位（%）',
        axisTick: {
            show: false
        },
        axisLine: {
            lineStyle: {
                color: '#57617B'
            }
        },
        axisLabel: {
            margin: 10,
            textStyle: {
                color: 'white',
                fontStyle: 'oblique',
                fontWeight: 'bold',
                fontSize: 15,
            }
        },
        splitLine: {
            lineStyle: {
                color: '#57617B'
            }
        }
    }],
    series: [{
        name: '移动',
        type: 'line',
        smooth: true,
        symbol: 'circle',
        symbolSize: 5,
        showSymbol: false,
        lineStyle: {
            normal: {
                width: 1
            }
        },
        areaStyle: {
            normal: {
                color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
                    offset: 0,
                    color: 'rgba(137, 189, 27, 0.3)'
                }, {
                    offset: 0.8,
                    color: 'rgba(137, 189, 27, 0)'
                }], false),
                shadowColor: 'rgba(0, 0, 0, 0.1)',
                shadowBlur: 10
            }
        },
        itemStyle: {
            normal: {
                color: 'rgb(137,189,27)',
                borderColor: 'rgba(137,189,2,0.27)',
                borderWidth: 12,
                opacity:0.6,
            }
        },
        data: []
    }, {
        name: '电信',
        type: 'line',
        smooth: true,
        symbol: 'circle',
        symbolSize: 5,
        showSymbol: false,
        lineStyle: {
            normal: {
                width: 1
            }
        },
        areaStyle: {
            normal: {
                color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
                    offset: 0,
                    color: 'rgba(0, 136, 212, 0.3)'
                }, {
                    offset: 0.8,
                    color: 'rgba(0, 136, 212, 0)'
                }], false),
                shadowColor: 'rgba(0, 0, 0, 0.1)',
                shadowBlur: 10
            }
        },
        itemStyle: {
            normal: {
                color: 'rgb(0,136,212)',
                borderColor: 'rgba(0,136,212,0.2)',
                borderWidth: 12,
                opacity:0.6,
            }
        },
        data: []
    }, {
        name: '联通',
        type: 'line',
        smooth: true,
        symbol: 'circle',
        symbolSize: 5,
        showSymbol: false,
        lineStyle: {
            normal: {
                width: 1
            }
        },
        areaStyle: {
            normal: {
                color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
                    offset: 0,
                    color: 'rgba(219, 50, 51, 0.3)'
                }, {
                    offset: 0.8,
                    color: 'rgba(219, 50, 51, 0)'
                }], false),
                shadowColor: 'rgba(0, 0, 0, 0.1)',
                shadowBlur: 10
            }
        },
        itemStyle: {
            normal: {
                color: 'rgb(219,50,51)',
                borderColor: 'rgba(219,50,51,0.2)',
                borderWidth: 12,
                opacity:0.6,
            }
        },
        data: []
    }, {
        name: '其他',
        type: 'line',
        smooth: true,
        symbol: 'circle',
        symbolSize: 5,
        showSymbol: false,
        lineStyle: {
            normal: {
                width: 1
            }
        },
        areaStyle: {
            normal: {
                color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
                    offset: 0,
                    color: 'rgba(254, 230, 25, 0.3)'
                }, {
                    offset: 0.8,
                    color: 'rgba(254, 230, 25, 0)'
                }], false),
                shadowColor: 'rgba(0, 0, 0, 0.1)',
                shadowBlur: 10
            }
        },
        itemStyle: {
            normal: {
                color: 'rgb(254, 230, 25)',
                borderColor: 'rgba(254, 230, 25,0.2)',
                borderWidth: 12,
                opacity:0.6,
            }
        },
        data: []
    } ]
};

myChart8.setOption(option8);

//订单占比
var myChart9 = echarts.init(document
    .getElementById('main9'));
option9 = {
    tooltip : {
        trigger: 'item',
        formatter: "{a} <br/>{b} : {c} ({d}%)"
    },
    visualMap: {
        show: false,
        min: 1,
        max: 50,
        /*min: 80,
         max: 600,*/
        inRange: {
            colorLightness: [0, 1]
        }
    },
    series : [
        {
            name:'访问来源',
            type:'pie',
            radius : ['15%','45%'],
            center: ['50%', '50%'],
            data:[].sort(function (a, b) { return a.value - b.value; }),
            roseType: 'radius',
            label: {
                normal: {
                    formatter:'{b}:{d}%',
                    textStyle: {
                        color: 'white',
                        fontStyle: 'oblique',
                        fontWeight: 'bold',
                        fontSize: 15,
                    }
                }
            },
            labelLine: {
                normal: {
                    lineStyle: {
                        color: 'white',
                        width: 2,
                    },
                    smooth: 0.2,
                    length: 8,
                    length2: 15
                }
            },
            itemStyle: {
                normal: {
                    color: '#080B22',
                    opacity:0.6,
                    shadowBlur: 50,
                    //shadowColor: '#000000'
                }
            },

            animationType: 'scale',
            animationEasing: 'elasticOut',
            animationDelay: function (idx) {
                return Math.random() * 200;
            }
        }
    ]
};

myChart9.setOption(option9);
window.onresize = function(){
    myChart.resize();
    myChart1.resize();
    myChart7.resize();
    myChart8.resize();
    myChart9.resize();
}